package com.lovo.project.servlet;

import com.lovo.project.model.ProportionDO;
import com.lovo.project.service.SalesVolumeService;
import com.lovo.project.service.impl.SalesVolumeServiceImpl;
import com.lovo.project.vo.ResultVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

@WebServlet(name = "ProportionServlet",value = "/proportion")
public class ProportionServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        SalesVolumeService salesVolumeService = new SalesVolumeServiceImpl();
        Integer countOne = salesVolumeService.findCountOne();
        Integer countTwo = salesVolumeService.findCountTwo();
        Integer countThree = salesVolumeService.findCountThree();
        List<String> axis = Arrays.asList("小于1000元","1000元到5000元","大于5000元");
        List<ProportionDO> series = new ArrayList<>();
        series.add(new ProportionDO(axis.get(0),countOne));
        series.add(new ProportionDO(axis.get(1),countTwo));
        series.add(new ProportionDO(axis.get(2),countThree));
        HashMap<String, Object> map = new HashMap<>();
        map.put("axis",axis);
        map.put("series",series);
        response.getWriter().println(ResultVO.success().add(map).toJson());
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
